package com.sevattal.service.leaves.controller;


import com.sevattal.common.base.result.R;
import com.sevattal.service.leaves.entity.Dept;
import com.sevattal.service.leaves.entity.Warehouse;
import com.sevattal.service.leaves.entity.vo.WarehouseVo;
import com.sevattal.service.leaves.service.WarehouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 仓库表 前端控制器
 * </p>
 *
 * @author Sevattal
 * @since 2021-08-28
 */
@Api(tags = "仓库信息管理")
@RestController
@RequestMapping("/admin/leaves/warehouse")
public class WarehouseController {

    @Autowired
    private WarehouseService warehouseService;

    @ApiOperation("新建仓库")
    @PostMapping("createWarehouse")
    public R createWarehouse(@ApiParam(value = "仓库对象",required = true) @RequestBody Warehouse warehouse){
        boolean result = warehouseService.createWarehouse(warehouse);
        if (result) {
            return R.ok().message("创建成功");
        }else{
            return R.error().message("创建失败");
        }
    }

    @ApiOperation("修改仓库")
    @PutMapping("updateWarehouse")
    public R updateWarehouse(@ApiParam(value = "仓库对象",required = true) @RequestBody Warehouse warehouse) {
        boolean result = warehouseService.updateWarehouse(warehouse);
        if (result) {
            return R.ok().message("修改成功");
        }else{
            return R.error().message("修改失败");
        }
    }

    @ApiOperation("删除仓库")
    @DeleteMapping("deleteWarehouse/{id}")
    public R deleteWarehouse(@ApiParam(value = "仓库id",required = true) @PathVariable String id) {
        boolean result = warehouseService.deleteWarehouse(id);
        if (result) {
            return R.ok().message("删除成功");
        }else{
            return R.error().message("删除失败");
        }
    }

    @ApiOperation("获取仓库信息ID")
    @GetMapping("getWarehouse/{id}")
    public R getWarehouse(@ApiParam(value="仓库id",required = true) @PathVariable String id){
        WarehouseVo warehouseVo = warehouseService.getWarehouse(id);
        return R.ok().data("warehouseInfo",warehouseVo);
    }

    @ApiOperation("获取仓库信息")
    @PostMapping("getWarehouseList")
    public R getWarehouseList(@ApiParam(value = "仓库对象",required =  true)  @RequestBody WarehouseVo warehouseVo){
        List<WarehouseVo> result = warehouseService.getWarehouseList(warehouseVo);
        return R.ok().data("warehouseList",result);
    }

}

